<!DOCTYPE html>
<html lang="en">

<head>
  <style>
    #left {
      float: left;
      width: 100%;
      height: 100%;
      background-color: #f1f1f1;
    }
  </style>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div id="left">
    <h1>Document...</h1>
    <button id="btn">test</button>
    <button id="btn1">更新</button>
    <br><br>
    <h1>本机信息：</h1>
    <label id="ipAddress">主进程获取IP地址：</label>
    <br><br>
    <label id="macAddress">主进程获取MAC地址：</label>
    <br><br>
    <label id="ipmacAddress">渲染进程获取MAC地址：</label>
  </div>
</body>

</html>
<script>
  const fs = require('fs')
  const os = require('os')
  const { ipcRenderer } = require('electron')
  document.getElementById('btn').onclick = () => {
    console.log('window-->', window)
    console.log('process-->', process, fs)
    
  }
  document.getElementById('btn1').onclick = () => {
    //请求检查更新
    ipcRenderer.send('checkUpdate')
  }

  //下载中收到的进度信息
  ipcRenderer.on('downloadProgress', (event, data) => {
    // me.prograssStyle.width = data.percent.toFixed(2) + "%";//更新进度条样式
    // me.stepText = "正在更新中(" + me.prograssStyle.width + ")...";
    console.log('data-->', data)
  })
  //监听请求更新响应，用来处理不同的事件
  ipcRenderer.on('message', (event, data) => {
    switch (data.status) {
      case -1:
        alert(data.msg)
        break
      case 1:
        console.log('正在升级')
        break
      case 2:
        alert(data.msg)
        break
    }
  })

  /* 获取本机信息 */
  //获取ip和mac地址
  ipcRenderer.send('getIpAddress');
  ipcRenderer.send('getMacAddress');
  ipcRenderer.on('ipAddress', (event, data) => {
    console.log('ipAddress-->', data)
    ipAddress.innerHTML += data
  })
  ipcRenderer.on('macAddress', (event, data) => {
    console.log('macAddress-->', data)
    macAddress.innerHTML += data
  })

  var mac = document.getElementById('ipmacAddress');
  mac.innerHTML += getMacAddress2();
  function getMacAddress2(){
    const interfaces = os.networkInterfaces();
    for (const name of Object.keys(interfaces)) {
      const interface1 = interfaces[name];
      for (const net of interface1) {
        if (net.mac) {
          return net.mac;
        }
      }
    }
    return '00:00:00:00:00:00';
  }
</script>